package com.Bigbluebook.Service;

import com.Bigbluebook.api.ApiConstants;
import com.Bigbluebook.entity.Like;
import com.Bigbluebook.entity.LikeStatus;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class LikeApiService {
    private LikeService likeService;
    private Retrofit retrofit;
    private Gson gson;

    public LikeApiService() {
        gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
                .create();
        retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
        likeService = retrofit.create(LikeService.class);
    }

    public void likePost(Like like, Callback<Like> callback) {
        Call<Like> call = likeService.likePost(like);
        call.enqueue(callback);
    }

    public void getLikesForPost(int postId, Callback<List<Like>> callback) {
        Call<List<Like>> call = likeService.getLikesForPost(postId);
        call.enqueue(callback);
    }

    public void unlikePost(int likeId, Callback<Void> callback) {
        Call<Void> call = likeService.unlikePost(likeId);
        call.enqueue(callback);
    }

    public void unlikeComment(int likeId, Callback<Void> callback) {
        Call<Void> call = likeService.unlikeComment(likeId);
        call.enqueue(callback);
    }

    public void likeComment(Like like, Callback<Like> callback) {
        Call<Like> call = likeService.likeComment(like);
        call.enqueue(callback);
    }

    public void checkLikeStatus(int postId, int userId, Callback<LikeStatus> callback) {
        Call<LikeStatus> call = likeService.checkLikeStatus(postId, userId);
        call.enqueue(callback);
    }
}
